package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.LikeDTO;
import com.woniu.pojo.Like;
import com.woniu.service.ILikeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaosong
 * @since 2023-04-01
 */
@RestController
@RequestMapping("/like")
public class LikeController extends BaseController{


    @Autowired
    private ILikeService likeService;
    //      分页查点赞信息。
    @PostMapping("/Search/{currentPage}/{pageSize}")
    @ApiOperation("分页条件查询")
    public Result SelectPageAll(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody LikeDTO likeDTO
    ){
        PageData pageData = likeService.search(currentPage,pageSize,likeDTO);
        return toDataResult(pageData);
    }

    //    按照id查询
    @GetMapping("/selectByid/{id}")
    @ApiOperation("ID查询点赞信息表")
    public Result  selectById(@PathVariable Integer id){

        Like like =  likeService.getById(id);
        return toDataResult(like);
    }

    //    批量删除
    @PostMapping("/delete")
    @ApiOperation("批量删除")
    public  Result deletes(@RequestBody List<String> list){
        boolean b =likeService.removeBatchByIds(list);
        return toResult(b);
    }

    //    新增
    @PostMapping("/save")
    @ApiOperation("新增")
    public Result save(@RequestBody Like like){
        boolean flag = likeService.saveLike(like);
        return toDataResult(flag);
    }
    //    修改
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result Update(@RequestBody Like like){
        Integer num  = likeService.updateLike(like);
        return toDataResult(num);
    }

}
